package com.ldwx.center.controller;

import com.ldwx.center.common.entity.Result;
import com.ldwx.center.common.entity.StatusCode;
import com.ldwx.center.model.Recruit;
import com.ldwx.center.model.vo.RecruitCompanyVo;
import com.ldwx.center.service.RecruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/recruit")
public class RecruitController {

    @Autowired
    private RecruitService service;

    /**
     * 查询所有招聘任务
     * @return
     */
    @RequestMapping("list")
    public Result findAll() {
        List<RecruitCompanyVo> list = null;
        Result result = new Result();
        try {
            list = service.findAll();
            result.setCode(StatusCode.OK);
            result.setMessage("查询成功");
            result.setData(list);
        }catch (Exception e){
            result.setCode(StatusCode.ERROR);
            result.setMessage("查询失败");
        }

        return result;
    }

    /**
     * 发布招聘
     * @param recruit
     * @return
     */
    @RequestMapping("addOrUpdate")
    public Result save(Recruit recruit) {
        try {
            service.save(recruit);
        }catch (Exception e){
            return new Result(true, StatusCode.OK, "操作失败");
        }

        return new Result(true, StatusCode.ERROR, "操作成功");
    }

}
